package com.anclick.mywatch;

import android.app.Activity;
import android.appwidget.AppWidgetManager;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageButton;

public class ConfigMainActivity extends Activity {

	private static final String TAG = "MyWatch";
	
	/// Widget Id
	private int mAppWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
	
	    /// 기본 선택값을 CANCELED로 지정해 사용자가 뒤로가기로 Activity를 닫는 경우 취소 결과값을 반환하도록 함.
	    setResult(RESULT_CANCELED);
	    
	    setContentView(R.layout.config_main);
	    
	    
	  /// 추가하려는 widgetID 추출
	    Intent intent = getIntent();
	    mAppWidgetId = intent.getIntExtra("SELECTED_WIDGET_ID", AppWidgetManager.INVALID_APPWIDGET_ID);
	    
	    /// 정상적인 경로로 호출되지 않은 경우 Activity를 종료한다.
	    if (mAppWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) {
	    	mAppWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
	    	Log.i(TAG, "1mAppWidgetId=" + mAppWidgetId);
	    	if (mAppWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) {
	    		Log.i(TAG, "2mAppWidgetId=" + mAppWidgetId);
	    		finish();
	    	} else {
	    		Log.i(TAG, "3mAppWidgetId=" + mAppWidgetId);
	    	}
	    } else {
	    	Log.i(TAG, "4mAppWidgetId=" + mAppWidgetId);
	    }
	    
	    ImageButton imgBtn1 = (ImageButton)findViewById(R.id.imgbtn01);
	    imgBtn1.setOnClickListener(new ImageButton.OnClickListener() {
			public void onClick(View v) {
				Intent intent = new Intent(ConfigMainActivity.this, ConfigSub1Activity.class);
				startActivity(intent);
			}
	    });
	    
	    ImageButton imgBtn2 = (ImageButton)findViewById(R.id.imgbtn02);
	    imgBtn2.setOnClickListener(new ImageButton.OnClickListener() {
			public void onClick(View v) {
				Intent intent = new Intent(ConfigMainActivity.this, ConfigSub2Activity.class);
				intent.putExtra("SELECTED_WIDGET_ID", mAppWidgetId);
				startActivity(intent);
			}
	    });
	}
}
